<template>
  <div class="card-common-inner wise-man-base-info">
    <first-level-title title="基础工作" />
    <van-loading v-if="isLoading && isLoadToday" type="spinner" color="#1989fa" />
    <div v-else class="base-info-content">
      <div class="base-info-item">
        <div class="item-total">
          <img src="~@/assets/imgs/wise/index/pic1.png" />
          <div class="info-text">
            <div class="text-item">
              <div class="title">昨日已装</div>
              <div class="value-nolink">{{ info.ZJ_VALUE || 0 }}</div>
            </div>
            <div class="text-item">
              <div class="title">今日已装</div>
              <div v-if="(currentInfo.ZJWC || 0) == 0" class="value-nolink">{{ currentInfo.ZJWC || 0 }}</div>
              <div v-else class="value" @click="handleOpen('zjwc')">{{ currentInfo.ZJWC }}</div>
            </div>
            <div class="text-item">
              <div class="title">今日在途</div>
              <div v-if="(currentInfo.ZJZT || 0) == 0" class="value-nolink">{{ currentInfo.ZJZT || 0 }}</div>
              <div v-else class="value" @click="handleOpen('zjzt')">{{ currentInfo.ZJZT }}</div>
            </div>
          </div>
        </div>
        <div class="item-detail">
          <div class="sub-title">昨日月累计</div>
          <div class="detail-text">
            <div class="text-item">
              <span class="sub-title">已装</span>
              <span class="sub-value">{{ info.ZJ_M_VALUE || 0 }}</span>
            </div>
            <div class="text-item">
              <span class="sub-title">环比</span>
              <span v-if="info.ZJ_HB >= 0" class="up">
                {{ info.ZJ_HB }}%
                <img src="~@/assets/imgs/publicline/index/arrow_up.png" />
              </span>
              <span v-else class="down">
                {{ info.ZJ_HB }}%
                <img src="~@/assets/imgs/publicline/index/arrow_down.png" />
              </span>
            </div>
          </div>
        </div>
      </div>
      <div class="base-info-item">
        <div class="item-total">
          <img src="~@/assets/imgs/wise/index/pic2.png" />
          <div class="info-text">
            <div class="text-item">
              <div class="title">昨日已装</div>
              <div class="value-nolink">{{ info.YJ_VALUE || 0 }}</div>
            </div>
            <div class="text-item">
              <div class="title">今日已装</div>
              <div v-if="(currentInfo.YJWC || 0) == 0" class="value-nolink">{{ currentInfo.YJWC || 0 }}</div>
              <div v-else class="value" @click="handleOpen('yjwc')">{{ currentInfo.YJWC }}</div>
            </div>
            <div class="text-item">
              <div class="title">今日在途</div>
              <div v-if="(currentInfo.YJZT || 0) == 0" class="value-nolink">{{ currentInfo.YJZT || 0 }}</div>
              <div v-else class="value" @click="handleOpen('yjzt')">{{ currentInfo.YJZT }}</div>
            </div>
          </div>
        </div>
        <div class="item-detail">
          <div class="sub-title">昨日月累计</div>
          <div class="detail-text">
            <div class="text-item">
              <span class="sub-title">已装</span>
              <span class="sub-value">{{ info.YJ_M_VALUE || 0 }}</span>
            </div>
            <div class="text-item">
              <span class="sub-title">环比</span>
              <span v-if="info.YJ_HB >= 0" class="up">
                {{ info.YJ_HB }}%
                <img src="~@/assets/imgs/publicline/index/arrow_up.png" />
              </span>
              <span v-else class="down">
                {{ info.YJ_HB }}%
                <img src="~@/assets/imgs/publicline/index/arrow_down.png" />
              </span>
            </div>
          </div>
        </div>
      </div>
      <div class="base-info-item">
        <div class="item-total">
          <img src="~@/assets/imgs/wise/index/pic3.png" />
          <div class="info-text">
            <div class="text-item">
              <div class="title">昨日已装</div>
              <div class="value-nolink">{{ info.XZ_VALUE || 0 }}</div>
            </div>
            <div class="text-item">
              <div class="title">今日已装</div>
              <div v-if="(currentInfo.XZWC || 0) == 0" class="value-nolink">{{ currentInfo.XZWC || 0 }}</div>
              <div v-else class="value" @click="handleOpen('xzwc')">{{ currentInfo.XZWC }}</div>
            </div>
            <div class="text-item">
              <div class="title">今日在途</div>
              <div v-if="(currentInfo.XZZT || 0) == 0" class="value-nolink">{{ currentInfo.XZZT || 0 }}</div>
              <div v-else class="value" @click="handleOpen('xzzt')">{{ currentInfo.XZZT }}</div>
            </div>
          </div>
        </div>
        <div class="item-detail">
          <div class="sub-title">昨日月累计</div>
          <div class="detail-text">
            <div class="text-item">
              <span class="sub-title">已装</span>
              <span class="sub-value">{{ info.XZ_M_VALUE || 0 }}</span>
            </div>
            <div class="text-item">
              <span class="sub-title">环比</span>
              <span v-if="info.XZ_HB >= 0" class="up">
                {{ info.XZ_HB }}%
                <img src="~@/assets/imgs/publicline/index/arrow_up.png" />
              </span>
              <span v-else class="down">
                {{ info.XZ_HB }}%
                <img src="~@/assets/imgs/publicline/index/arrow_down.png" />
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import firstLevelTitle from '@/components/common/firstLevelTitle.vue'

import { baseInfo, baseInfoCurrnet } from '@/api/publicline/wise.js'
import Vue from 'vue'
import { USER_INFO } from '@/store/mutation-types'

export default {
  components: { firstLevelTitle },
  data() {
    return {
      isLoading: true,
      isLoadToday: true,
      info: {},
      currentInfo: {}
    }
  },
  mounted() {
    this.getInfo()
  },
  methods: {
    // 昨日完成
    async getInfo() {
      this.isLoading = true
      const res = await baseInfo({ gridId: this.$dataPermission })
      const { result, success } = res
      if(success) {
        this.info = result[0] || {}
        this.isLoading = false
      }
    },
    // 今日
    async getCurrentInfo() {
      this.isLoadToday = true
      const res = await baseInfoCurrnet({ LVL_ID: this.$dataPermission })
      const { result, success } = res
      if(success) {
        this.currentInfo = result[0] || {}
        this.isLoadToday = false
      }
    },
    handleOpen(title) {
      this.$open.call(this, '/publicline/monitor-users',
        {
          type: 'zyx',
          lvlid: Vue.ls.get(USER_INFO).username,
          title
        }
      )
    }
  }
}
</script>
<style lang="less" scoped>
@import '~@/assets/less/card.less';
.wise-man-base-info {
  .base-info-content {
    .base-info-item {
      margin-top: 20px;
    }
    .item-total,
    .item-detail {
      display: flex;
      align-items: center;
      justify-content: flex-start;
    }
    .info-text,
    .detail-text {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        text-align: center;
        padding-left: 12px;
    }
    .info-text .text-item {
      width: 33%;
    }
    .detail-text .text-item {
      width: 50%;
    }
    .sub-title {
      font-size: 12px;
      color: #999;
    }
    .sub-value {
      font-size: 12px;
      padding-left: 2px;
    }
    .item-total {
      margin-bottom: 6px;
      img {
        width: 70px;
      }
      .text-item {
        border-left: 1px solid rgba(245,245,245,1);
      }
      .title {
        color: #666;
      }
      .value {
        font-size: 18px;
        margin-top: 2px;
        color: #4D98FF;
        text-decoration: underline;
        margin-bottom: 4px;;
      }
      .value-nolink {
        font-size: 18px;
        margin-top: 2px;
        color: #666;
        margin-bottom: 4px;;
      }
    }
    .item-detail {
      background: #F3F7FA;
      padding: 4px 0;
      font-size: 12px;
      > .sub-title {
        width: 70px;
        text-align: center;
      }
      .text-item {
        border-left: 1px solid #999;
        color: #999;
      }
      img {
        width: 10px;
      }
      .up {
        color: #FF6024;
      }
      .down {
        color: #40BB3F;
      }
    }
  }
}
</style>
